﻿// LTDMC_AxisIO_Dlg.cpp: 实现文件
//

#include "pch.h"
#include "SakerProject.h"
#include "LTDMC_AxisIO_Dlg.h"
#include "afxdialogex.h"

#include "xxFileProcess.h"
#include "mmFile_Paras.h"
#include "xxWidgetControl.h"

// CLTDMC_AxisIO_Dlg 对话框
CLTDMC_AxisIO_Dlg * m_LTDMC_AxisIO;

IMPLEMENT_DYNAMIC(CLTDMC_AxisIO_Dlg, CDialogEx)

CLTDMC_AxisIO_Dlg::CLTDMC_AxisIO_Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_LTDMC_AxisIO, pParent)
{

}

CLTDMC_AxisIO_Dlg::~CLTDMC_AxisIO_Dlg()
{
}

void CLTDMC_AxisIO_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CLTDMC_AxisIO_Dlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_Save, &CLTDMC_AxisIO_Dlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_SaveAll, &CLTDMC_AxisIO_Dlg::OnBnClickedButtonSaveall)
	ON_CBN_SELCHANGE(IDC_COMBO_AxisName, &CLTDMC_AxisIO_Dlg::OnCbnSelchangeComboAxisname)
END_MESSAGE_MAP()


// CLTDMC_AxisIO_Dlg 消息处理程序


BOOL CLTDMC_AxisIO_Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	xx::InitCB(this, IDC_COMBO_AxisName, mmLTDMC.vecAxisNames, CurAxis);
	InitCurAxis();

	return TRUE;
}

void CLTDMC_AxisIO_Dlg::InitCurAxis() {
	mmLTDMC.Axis[CurAxis].Servo.LowTrig = xx::WriteCK(this, IDC_CHECK_Servo, mmLTDMC.Axis[CurAxis].Servo.LowTrig);
	mmLTDMC.Axis[CurAxis].LimitP.LowTrig = xx::WriteCK(this, IDC_CHECK_LimitP, mmLTDMC.Axis[CurAxis].LimitP.LowTrig);
	mmLTDMC.Axis[CurAxis].LimitN.LowTrig = xx::WriteCK(this, IDC_CHECK_LimitN, mmLTDMC.Axis[CurAxis].LimitN.LowTrig);
	mmLTDMC.Axis[CurAxis].Emerg.LowTrig = xx::WriteCK(this, IDC_CHECK_Emerg, mmLTDMC.Axis[CurAxis].Emerg.LowTrig);
	mmLTDMC.Axis[CurAxis].LimitO.LowTrig = xx::WriteCK(this, IDC_CHECK_LimitO, mmLTDMC.Axis[CurAxis].LimitO.LowTrig);
	mmLTDMC.Axis[CurAxis].SoftP.LowTrig = xx::WriteCK(this, IDC_CHECK_SoftP, mmLTDMC.Axis[CurAxis].SoftP.LowTrig);
	mmLTDMC.Axis[CurAxis].SoftN.LowTrig = xx::WriteCK(this, IDC_CHECK_SoftN, mmLTDMC.Axis[CurAxis].SoftN.LowTrig);
	mmLTDMC.Axis[CurAxis].InPos.LowTrig = xx::WriteCK(this, IDC_CHECK_InPos, mmLTDMC.Axis[CurAxis].InPos.LowTrig);
	mmLTDMC.Axis[CurAxis].EZ.LowTrig = xx::WriteCK(this, IDC_CHECK_EZ, mmLTDMC.Axis[CurAxis].EZ.LowTrig);
	mmLTDMC.Axis[CurAxis].Ready.LowTrig = xx::WriteCK(this, IDC_CHECK_Ready, mmLTDMC.Axis[CurAxis].Ready.LowTrig);
	mmLTDMC.Axis[CurAxis].DSTP.LowTrig = xx::WriteCK(this, IDC_CHECK_DSTP, mmLTDMC.Axis[CurAxis].DSTP.LowTrig);
}

void CLTDMC_AxisIO_Dlg::OnBnClickedButtonSave()
{
	CString iniField;
	iniField.Format(L"LTDMC_Axis_%02d... ...", CurAxis);
	CString iniCurrentPath = mmFile_Paras.iniModelPath();
	mmLTDMC.Axis[CurAxis].Servo.LowTrig = xx::DefaultCK(this, IDC_CHECK_Servo, iniField, L"LowTrig_Servo", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].Alarm.LowTrig = xx::DefaultCK(this, IDC_CHECK_Alarm, iniField, L"LowTrig_Alarm", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].LimitP.LowTrig = xx::DefaultCK(this, IDC_CHECK_LimitP, iniField, L"LowTrig_LimitP", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].LimitN.LowTrig = xx::DefaultCK(this, IDC_CHECK_LimitN, iniField, L"LowTrig_LimitN", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].Emerg.LowTrig = xx::DefaultCK(this, IDC_CHECK_Emerg, iniField, L"LowTrig_Emerg", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].LimitO.LowTrig = xx::DefaultCK(this, IDC_CHECK_LimitO, iniField, L"LowTrig_LimitO", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].SoftP.LowTrig = xx::DefaultCK(this, IDC_CHECK_SoftP, iniField, L"LowTrig_SoftP", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].SoftN.LowTrig = xx::DefaultCK(this, IDC_CHECK_SoftN, iniField, L"LowTrig_SoftN", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].InPos.LowTrig = xx::DefaultCK(this, IDC_CHECK_InPos, iniField, L"LowTrig_InPos", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].EZ.LowTrig = xx::DefaultCK(this, IDC_CHECK_EZ, iniField, L"LowTrig_EZ", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].Ready.LowTrig = xx::DefaultCK(this, IDC_CHECK_Ready, iniField, L"LowTrig_Ready", iniCurrentPath);
	mmLTDMC.Axis[CurAxis].DSTP.LowTrig = xx::DefaultCK(this, IDC_CHECK_DSTP, iniField, L"LowTrig_DSTP", iniCurrentPath);
}


void CLTDMC_AxisIO_Dlg::OnBnClickedButtonSaveall()
{
	for (int i = 0; i < mmLTDMC.AxisNum(); i++) {
		CString iniField;
		iniField.Format(L"LTDMC_Axis_%02d... ...", CurAxis);
		CString iniCurrentPath = mmFile_Paras.iniModelPath();
		mmLTDMC.Axis[CurAxis].Servo.LowTrig = xx::DefaultCK(this, IDC_CHECK_Servo, iniField, L"LowTrig_Servo", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].Alarm.LowTrig = xx::DefaultCK(this, IDC_CHECK_Alarm, iniField, L"LowTrig_Alarm", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].LimitP.LowTrig = xx::DefaultCK(this, IDC_CHECK_LimitP, iniField, L"LowTrig_LimitP", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].LimitN.LowTrig = xx::DefaultCK(this, IDC_CHECK_LimitN, iniField, L"LowTrig_LimitN", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].Emerg.LowTrig = xx::DefaultCK(this, IDC_CHECK_Emerg, iniField, L"LowTrig_Emerg", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].LimitO.LowTrig = xx::DefaultCK(this, IDC_CHECK_LimitO, iniField, L"LowTrig_LimitO", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].SoftP.LowTrig = xx::DefaultCK(this, IDC_CHECK_SoftP, iniField, L"LowTrig_SoftP", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].SoftN.LowTrig = xx::DefaultCK(this, IDC_CHECK_SoftN, iniField, L"LowTrig_SoftN", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].InPos.LowTrig = xx::DefaultCK(this, IDC_CHECK_InPos, iniField, L"LowTrig_InPos", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].EZ.LowTrig = xx::DefaultCK(this, IDC_CHECK_EZ, iniField, L"LowTrig_EZ", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].Ready.LowTrig = xx::DefaultCK(this, IDC_CHECK_Ready, iniField, L"LowTrig_Ready", iniCurrentPath);
		mmLTDMC.Axis[CurAxis].DSTP.LowTrig = xx::DefaultCK(this, IDC_CHECK_DSTP, iniField, L"LowTrig_DSTP", iniCurrentPath);
	}
}




void CLTDMC_AxisIO_Dlg::OnCbnSelchangeComboAxisname()
{
	CurAxis = ((CComboBox*)GetDlgItem(IDC_COMBO_AxisName))->GetCurSel();
	InitCurAxis();
}
